<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const p = new Promise((resolve, rejcet)=>{
            setTimeout(()=>{
                resolve('用户数据')
            }, 1000)
        })
        //then方法的返回结果是Promise对象，对象状态由回调函数的执行结果决定
        //1. 如果回调函数返回结果是非Promise类型，状态为成功，返回值为result中的value值
        //2.如果回调函数返回Promise类型，则then的返回值就是回调函数返回的promise对象
        let result = p.then(value=>{
            console.log(value)
            //返回非promise对象
            //return 123
            //返回promise对象
            return new Promise((resolve, rejcet)=>resolve('ok'))
        }, reason=>{
            console.log(reason)
        })

        console.log(result)

        //then支持链式调用
        //p.then(value=>{},reason=>{}).then(value=>{},reason=>{})
    </script>
</body>
</html>